/**
 * 出勤日志管理初始化
 */
var DoorAttendance = {
    id: "DoorAttendanceTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
DoorAttendance.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: '编号', field: 'id', visible: true, align: 'center', valign: 'middle',formatter: function (value, row, index) {


                    var a = "";
                    if (row.status == "迟到"||row.status == "早退" ) {
                        var a = '<span style="color: #0089ff">' + value + '</span>';
                        return a;
                    }else {
                        var a = '<span class="value">' + value + '</span>';
                        return a;
                    }
                }
            },
            {title: '姓名', field: 'name', visible: true, align: 'center', valign: 'middle',formatter: function (value, row, index) {


                    var a = "";
                    if (row.status == "迟到"||row.status == "早退" ) {
                        var a = '<span style="color: #0089ff">' + value + '</span>';
                        return a;
                    }else {
                        var a = '<span class="value">' + value + '</span>';
                        return a;
                    }
                }
            },
            {title: '时间', field: 'datetime', visible: true, align: 'center', valign: 'middle',formatter: function (value, row, index) {


                    var a = "";
                    if (row.status == "迟到"||row.status == "早退" ) {
                        var a = '<span style="color: #0089ff">' + value + '</span>';
                        return a;
                    }else {
                        var a = '<span class="value">' + value + '</span>';
                        return a;
                    }
                }
            },
            {title: '部门', field: 'department', visible: true, align: 'center', valign: 'middle',formatter: function (value, row, index) {


                    var a = "";
                    if (row.status == "迟到"||row.status == "早退" ) {
                        var a = '<span style="color: #0089ff">' + value + '</span>';
                        return a;
                    }else {
                        var a = '<span class="value">' + value + '</span>';
                        return a;
                    }
                }
            },
            {title: '状态', field: 'status', visible: true, align: 'center', valign: 'middle',formatter:function(value,row,index){

                    var a = "";
                    if (row.status == "迟到"||row.status == "早退" ) {
                        var a = '<span style="color: #0089ff">' + value + '</span>';
                        return a;
                    }else {
                        var a = '<span class="value">' + value + '</span>';
                        return a;
                    }a



                }}
            //     },
            //
            // {title: '预留', field: 'reserve', visible: true, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
DoorAttendance.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        DoorAttendance.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加出勤日志
 */
DoorAttendance.openAddDoorAttendance = function () {
    var index = layer.open({
        type: 2,
        title: '添加出勤日志',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/doorAttendance/doorAttendance_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看出勤日志详情
 */
DoorAttendance.openDoorAttendanceDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '出勤日志详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/doorAttendance/doorAttendance_update/' + DoorAttendance.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除出勤日志
 */
DoorAttendance.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/doorAttendance/delete", function (data) {
            Feng.success("删除成功!");
            DoorAttendance.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("doorAttendanceId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询出勤日志列表
 */
DoorAttendance.search = function () {
    var queryData = {};
    queryData['name'] = $("#name").val();
    queryData['department'] = $("#department").val();
    queryData['status'] = $("#status").val();

    DoorAttendance.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = DoorAttendance.initColumn();
    var table = new BSTable(DoorAttendance.id, "/doorAttendance/list", defaultColunms);
    table.setPaginationType("client");
    DoorAttendance.table = table.init();
});
